import {defineStore} from "pinia"
import {ref} from "vue"
import {MessageOptions, NotificationOptions} from 'naive-ui'
import {TipMessageTypeConst, TipMessageType, TipNotificationTypeConst, TipNotificationType} from '../const/tip-const.ts'

/**
 * 和提示相关的状态管理仓库
 */
export const useTipStore = defineStore('tipStore', () => {
  // Message 信息提示
  const messageStatus = ref<number>(0)
  const messageContent = ref<string>('')
  const messageType = ref<TipMessageType>(TipMessageTypeConst.INFO)
  const messageOptions = ref<MessageOptions>()
  const getMessageStatus = () => messageStatus.value
  const getMessageContent = () => messageContent.value
  const getMessageType = () => messageType.value
  const getMessageOptions = () => messageOptions.value
  const message = (content: string, type: TipMessageType = TipMessageTypeConst.INFO, options?: MessageOptions) => {
    messageStatus.value++
    messageContent.value = content
    messageType.value = type
    messageOptions.value = options
  }

  // Notification 通知提示
  const notificationStatus = ref<number>(0)
  const notificationType = ref<TipNotificationType>(TipNotificationTypeConst.INFO)
  const notificationOptions = ref<NotificationOptions>({
    content: '通知提示',
    meta: '通知提示内容',
  })
  const getNotificationStatus = () => notificationStatus.value
  const getNotificationType = () => notificationType.value
  const getNotificationOptions = () => notificationOptions.value
  const notification = (options: NotificationOptions, type: TipNotificationType = TipNotificationTypeConst.INFO) => {
    notificationStatus.value++
    notificationType.value = type
    notificationOptions.value = options
  }

  return {
    getMessageStatus,
    getMessageContent,
    getMessageType,
    getMessageOptions,
    message,
    getNotificationStatus,
    getNotificationType,
    getNotificationOptions,
    notification,
  }
})
